<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>凉山州中考报名信息管理系统</title>
    <link rel="stylesheet" href="css/newStyle.css"	th:href="@{css/newStyle.css}">
    <link rel="stylesheet" type="text/css" href="css/bwyStyle.css"	th:href="@{css/bwyStyle.css}" />
    <link href="css/bootstrap.min.css" rel="stylesheet" th:href="@{css/bootstrap.css}" />
    <script src="js/jquery-3.2.1.min.js" th:href="@{js/jquery-3.2.1.min.js}"></script>
    <script src="js/bootstrap.js" th:href="@{js/bootstrap.js}"></script>
</head>
<body>
<!-- 返回上一级提交表单 -->
<form id="returnBack" action="check" method="post">
	<input type="hidden" th:value="${junior.byzxdm}" name="byzxdm" />
	<input type="hidden" th:value="${junior.byzxmc}" name="byzxmc" />
	<input type="hidden" th:value="${junior.password}" name="password" />
</form>
  <div class="container mainBox " th:object="${junior}">
            <div class="row text-center">
                <div>
                    <h1>凉山州中考报名信息管理系统(初级中学)</h1>
                </div>
            </div>
            <div class="row">
                <p class="tips" style="text-align: center;">本批次网上报名时间限制为：2019年4月15日至2019年4月29日</p>
            </div>
            <div class="clearfix visible-xs-block"></div>
            <form id="form1" action="#" method="post">
            <div class="row">
                <div class="col-xs-6 col-md-6 text-left">
                   <div class="fl" ><span th:text="${junior.byzxmc}+' 导入学籍'"></span></div>
                </div>
                <div class="col-xs-6 col-md-6 text-right">
                    <a id="backtop" class="loginOut" onclick="is_submit(1)">[返&nbsp&nbsp&nbsp&nbsp回]</a>
                    <a id="loginOut" class="loginOut" onclick="is_submit(2)">[安全退出]</a>
                </div>
            </div>
            </form>
            <div class="row">
                <div class="panel panel-success">
                    <div class="panel-heading text-center">
                        <h3 class="panel-title">导入学籍信息
                        </h3>
                    </div>
                </div>
            </div>
           
           <form action="upload" method="post" id="fileForm" enctype="multipart/form-data">
           <div class="row" style="min-height:200px">
               <div class="form-group">
	            		<input  class="center-block" type="file" id="excelfile" name="file"  accept=".xls,.xlsx"/>
               </div>
             </div>
            <div class="row">
                  <p id="tips" ></p>
            </div>
              <div class="row" id="sub">
                    <button type="button" class="btn btn-primary btn-block" onclick="uploadFile()" >导入学籍</button>
            </div>
            <div class="row" id="sub">
                    <button type="button" class="btn btn-primary btn-block" onclick="is_submit(3)" >导出模板</button>
            </div>            
             </form>
                        
 </div>          
</body>
<script src="js/commen.js"></script>
<script>
    /*
	//退出按钮
	$('#loginOut').on('click', function() {
		alert("安全退出");
		$.ajax({
			type : "post",
			url : "loginOut",//提交的地址
			//data:$("#ami_form").serialize(),
			data : {},
			dataType : "json",
			success : function(data) {
				console.log(data);
				alert("提交成功")
				//看一下data返回是否成功，成功在话弹提交成功，反之失败
				 //window.location.href="/index";
				 location.href="";
			},
			error : function(error) {
				//提交失败
				console.log(error);
				alert("提交失败")
			}
		})
	})
	*/

</script>

<script type="text/javascript">
	function uploadFile() {
		$("#sub button").attr("disabled","disabled");
		//showLoading();
		var type = "file";
		var id = "excelfile";
		var formData = new FormData();
		formData.append(type, $("#" + id)[0].files[0]);
		$.ajax({
			type : "POST",
			url : "doUpload",
			data : formData,//要传到后台的参数
			secureuri : false,//是否启用安全提交,默认为false
			//fileElementId : 'file',//文件选择框的id属性
			//dataType : 'json',//服务器返回的格式
			processData : false,
			contentType : false,
			async : true,
			success : function(data) {
				//closeLoading();
				if (data == 'ok') {
					setTimeout(function(){
						//自己的逻辑
						alert("上传成功");
						//$("#tips").text("上传成功");
					},3000);
					
				}else{
					$("#tips").html(data);
				}
			},
			error : function(data, status, e) {
				//alert("导入失败，请检查身份证号是否重复");
				//自己的逻辑
				//$("#tips").text("上传失败");
				$("#tips").html(data);
			}
		});
		$("#sub button").removeAttr("disabled");
	}

	function importData_bak() {
		var file = $("#excelfile").val();
		var strFileName = file
				.replace(/^.+?\\([^\\]+?)(\.[^\.\\]*?)?$/gi, "$1"); //正则表达式获取文件名，不带后缀
		var fileExt = file.replace(/.+\./, ""); //正则表达式获取后缀
		var data = new Object();
		fileName = strFileName + "." + fileExt;
		startRow = 2;
		$.ajax({
			url : "importStatus",
			type : "POST",
			data : {"fileName":fileName,
				    "startRow":startRow},
		   // dataType : "xml",
			success : function(data) {
				$("#tips").text("导入成功");
			},
			error:function(data){
				$("#tips").text("导入失败");
			}
		});
	}
	
	function is_submit(value) {
	    var form1 = $("#returnBack");
	    if (value == 1) {    	//	返回上级
	        var id = $("#id").val();
	        form1.action = "/check";
	        // $("#backtop").attr("action","/check");
	        $("#returnBack").attr("action","check");
	        form1.submit();
	    }
	    if (value == 2) {	//安全退出
	        form1.action = "logout";
	        $("#loginOut").attr("action", "/junior/logout");
	        $("#returnBack").attr("action","logout");
	        form1.submit();

	    }
	    if (value == 3) {	//导出模板
	    	fileForm.action = "/junior/doFileDownload";
	        //$("#loginOut").attr("action", "/junior/doFileDownload");
	        //$("#returnBack").attr("action","logout");
	        fileForm.submit();

	    }
	   
	}
</script>

</html>

